<template>
	<view class="playerTrading">
		<view class="title">
			<view class="title_bg">
				玩家市场
			</view>
		</view>
		<view class="prize-overview-content-top">
			<view v-for="(item, index) in typeList" :key="index" :class="{ 'bjimg': item.id === shopId }"
				@click="handleProductProbabilityClick(item)">
				<image :src="item.thumb" mode="aspectFill">
					<text class="name">{{ item.title }}</text>
			</view>
		</view>
		<view class="search">
			<!-- 搜索框 -->
			<view class="search-input-wrapper">
				<input type="text" icon="search" v-model="skuname" placeholder="搜索商品" placeholder-class="placeholder" />
				<button class="search-btn" @click="selectAll()">搜索</button>
			</view>
			<image class="seach-img" src="../../static/manghe/sort.png" mode="aspectFill" @click="toggleSortOrder()">
			</image>
		</view>
		<view v-if="!selectList.length && init" style="height: 70vh;overflow: hidden;">
			<NoData></NoData>
		</view>
		<!-- 商品列表 -->
		<view class="prize-overview-content-bottom">
			<view class="content" v-for="(item, index) in selectList" :key="index" @click="getDetail(item.skuId)">
				<image :src="item.detailImages" mode="aspectFill">
					<view class="box-list">
						<view class="name">{{ item.name }}</view>
						<view class="price">
							{{ item.transactionPrice }} 镇北币
						</view>
					</view>
					<view class="grade">
						传说
					</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			shopId: '', //商品id
			// 分类列表
			typeList: [],
			// 转让列表
			selectList: [],
			// 搜索商品名
			skuname: "",
			sortOrder: 1, // 默认升序
			init: false,
		}
	},
	onShow() {
		this.getType();
		this.selectAll();
	},
	methods: {
		// 点击商品概率
		handleProductProbabilityClick(item) {
			this.shopId = item.id

			this.selectAll("", item.id)
		},
		async toggleSortOrder() {
			// 切换排序顺序
			this.sortOrder = this.sortOrder === 1 ? 2 : 1;
			// 调用 selectAll 方法
			console.log(this.typeList);

			await this.selectAll(this.shopId);
		},
		async getType() {
			// 品牌类型
			await this.$http('/sale/selectGoodsTags', "get").then(res => {
				this.typeList = res.data
				// this.shopId = this.typeList[0].title
				// console.log(this.shopId);
				// this.selectAll(this.typeList[0].id, "")
			})
		},
		// 转让列表
		async selectAll(shopId) {
			await this.$http('/sale/selectAll', "get", {
				name: this.skuname,
				tagId: shopId ? shopId : "",
				ascOrDesc: this.sortOrder
			}).then(res => {
				this.selectList = res.data.list
				this.init = true
			})
		},
		getDetail(skuId) {
			uni.navigateTo({
				url: "/pages/playerTrading/details?skuId=" + skuId
			})
		}
	}
}
</script>

<style scoped lang="scss">
page {
	background: url(../../static/bgColor.png) center/ cover no-repeat;

	.playerTrading {
		width: 100%;
		height: 100%;
		padding: 20rpx 30rpx;
		box-sizing: border-box;

		.title {
			height: 100rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 900;
			color: #f3d26e;
			font-size: 35rpx;

			.title_bg {
				background: url('../../static/manghe/top.png');
				background-size: contain;
				background-repeat: no-repeat;
				width: 400rpx;
				text-align: center;
				height: 100rpx;
				background-position: center;
				line-height: 100rpx;
			}
		}

		.prize-overview-content-top {
			width: 100%;
			height: 15%;
			display: flex;
			align-items: center;
			// justify-content: space-between;
			overflow-x: auto;

			view {
				width: 120rpx;
				height: 120rpx;
				background-image: url('https://zsw-bimface-res.izsw.net/img/bim-community/%E6%9C%AA%E7%82%B9%E5%87%BB.png');
				background-repeat: no-repeat;
				background-size: 100% 100%;
				display: flex;
				flex-shrink: 0;
				/* 防止内容被压缩 */
				flex-wrap: wrap;
				justify-content: center;
				align-content: center;
				margin-right: 20rpx;

				image {
					width: 70rpx;
					height: 70rpx;
				}

				text {
					display: inline-block;
					width: 100%;
					height: 30rpx;
					padding: 0 10rpx;
					color: white;
					text-align: center;
				}

				.name {
					font-size: 20rpx;
				}

				.probability {
					font-size: 17rpx;
				}
			}

			.bjimg {
				background-image: url('https://zsw-bimface-res.izsw.net/img/bim-community/%E5%B7%B2%E7%82%B9%E5%87%BB.png');
				background-repeat: no-repeat;
				background-size: 100% 100%;
			}
		}

		.search {
			// width: 95%;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.search-input-wrapper {
				height: 80rpx;
				margin: 30rpx 0;
				flex: 1;
				background-color: #fff;
				padding: 0 30rpx;
				font-weight: 100;
				display: flex;
				align-items: center;
				position: relative;
				border-radius: 15rpx;

				.icon-search {
					margin-right: 10rpx;
					color: #000;
					z-index: 999;
				}

				input {
					background-color: transparent;
					padding: 0;
					height: 90%;
					line-height: 70rpx;
					color: #000;
				}

				.search-btn {
					width: 130rpx;
					height: 70rpx;
					line-height: 70rpx;
					font-size: 32rpx;
					position: absolute;
					right: 5%;
					color: #fff;
					background: rgb(108, 67, 255);
				}
			}

			.seach-img {
				width: 40rpx;
				height: 40rpx;
				margin-right: 20rpx;
				margin-left: 40rpx;
			}

		}

		.prize-overview-content-bottom {
			width: 98%;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			overflow: auto;
			margin-bottom: 120rpx;

			.content {
				width: 330rpx;
				height: 450rpx;
				background-image: url('https://zsw-bimface-res.izsw.net/img/bim-community/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20240320090054.png');
				background-repeat: no-repeat;
				background-size: 100% 100%;
				margin-bottom: 30rpx;
				display: flex;
				flex-wrap: wrap;
				align-content: center;
				position: relative;

				.grade {
					width: 100rpx;
					height: 40rpx;
					color: white;
					font-size: 28rpx;
					position: absolute;
					top: 5rpx;
					left: 20rpx;
				}

				image {
					width: 80%;
					height: 200rpx;
					margin: 0 auto;
				}

				.box-list {
					margin-left: 20rpx;
					margin-top: 20rpx;

					.name {
						color: white;
						margin-bottom: 10rpx;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						/* 限制在一个块元素显示的文本的行数 */
						overflow: hidden;
						/* 隐藏超出的内容 */
						text-overflow: ellipsis;
						/* 显示省略符号来表示文本被截断 */
					}

					.price {
						color: white;
					}
				}
			}
		}
	}
}
</style>